package com.kaifamiao.schedule;

public class SleepTest {

    public static void startThread(String name, int priority) {
        Runnable runnable = () -> {
            String tName = Thread.currentThread().getName();
            for (int i = 1; i < 6; i++) {
                System.out.printf( "%s(%d): before sleep\n", tName, i );
                try {
                    Thread.sleep(1L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.printf( "%s(%d): after sleep\n", tName, i );
            }
        };
        Thread t = new Thread(runnable, name);
        t.setPriority(priority);
        t.start();
    }

    public static void main(String[] args) {
        startThread("孙悟空", Thread.MIN_PRIORITY);
        startThread("银角大王", Thread.NORM_PRIORITY);
        startThread("九尾狐", Thread.MAX_PRIORITY);
    }

}
